<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<template #top>
				<view class=""style="background-color: #F8F8F8;">
					<view class="u-p-20" style="background-color: #F8F8F8;">
						<u-search :searchIconFlag="true" v-model="searchText" input-align="center" placeholder="商品名称搜索" height="70" :border-color="'#FFBB1A'" :bg-color="'#F8F8F8'" 	:show-action="false" @change="reloadFn" @search="reloadFn"></u-search>
					</view>
				</view>
			</template>
			
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
				<view class="payorder-section">
					<view class="u-flex">
						<view class="" style="flex:1;">
							<view class="u-flex" >
								<image :src="item.itemResourceUrl?item.itemResourceUrl:defaultLogo" mode="" class="section-image" ></image>
								<view class="section-list ">
									<view class="section-item u-m-l-18">
										<view class="section-item-name " style="width:94%;">
										{{item.itemName}}
										</view>
										<view class="u-font-24 u-m-t-10 u-m-b-20" v-if="item.specification" style=" display: inline-block; color: #999;background-color: #f8f8f8;padding: 10rpx 12rpx;border-radius: 10rpx;">
											{{item.specification}}
										</view>
									</view>
								</view>
							</view>
							<view class="section-item-count u-m-t-20 u-flex">
								合同号 <text class="u-m-l-10">{{item.contractNo}}</text>
								<text class="u-m-l-20 u-m-r-20" style="color:#999;font-size: 10rpx;">|</text>
								生产日期 <text class="u-m-l-10" >{{$u.timeFormat(item.dateOfManufacture,'yyy-mm-dd')}}</text>
							</view>
						</view>
						<view class="u-flex u-col-center u-row-between u-m-l-20" style="height: 100%;">
							<view class="section-btn-box " @click="$mRouter.push({route:'/pages/owners/billofEntryMange/editBillofEntry?type=edit&id='+item.dockReceiptId})">
								<image src="/static/owners/editContract.png" mode="" style="height: 46rpx;width: 46rpx;"></image>
							</view>
						</view>
						
					</view>
				
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import { useShopStore } from '@/store/shop.js';
	import { mapState } from 'pinia';
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchText:'',
			}
		},
		computed:{
			...mapState(useShopStore, {storeShop: 'shop'})
		},
		methods: {
			reloadFn(){
				this.$refs.paging.reload();
			},
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					brandownerId:this.storeShop.id,
				}
				if(this.searchText!==''){
					params.idOrName = this.searchText;
				}
				uni.showLoading({
					title: '加载中...',
					mask: false
				});
				const res = await this.$newHttp.get('api/Product/GetPagedDockReceiptByItem', {params:params} );
				uni.hideLoading({
					title: '加载中...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			// display: flex;
			// align-items: center;
			box-sizing: border-box;
			padding: 25rpx 0;
			margin-bottom: 20rpx;
			.section-item-count{
				font-size: 24rpx;
				color: #999;
			}
			.section-image{
				width: 100rpx;
				height: 100rpx;
				display: block;
				border-radius: 10rpx;
				// margin-right: 32rpx;
			}
			.section-list{
				flex: 1;
				overflow: hidden;
				// margin-left: 20rpx;
				.section-btn{
					width: 160rpx;
					margin-left: 10rpx;
					height:70rpx;
					border-radius: 35rpx;
					border: 1rpx solid #FFBB1A;
					color: #FFBB1A;
					text-align: center;
					line-height: 70rpx;
				}
				.section-btn-disabled{
					border-color:#999999;
					color: #999999;
				}
				.section-item{
					width: 100%;
					.section-item-name{
						font-size: 32rpx;
						font-weight: 500;
					}
					
					
				}
			}
			.section-btn-box{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				>.btn-text{
					font-size: 20rpx;
					margin-top: 10rpx;
				}
			}
			
		}
		
	}


</style>
